package model

import (
	"gitee.com/kisgod/Lamborighi/Server/config"
	"gitee.com/kisgod/Lamborighi/Server/util"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

var DBIns *gorm.DB

func init() {
	if DBIns == nil {
		var err error
		DBIns, err = gorm.Open("mysql", config.GetConfigDns())
		DBIns.LogMode(true)
		DBIns.SetLogger(util.Logger.GetSqlLogger())
		util.Logger.Info(config.GetConfigDns())

		if err != nil {
			util.Logger.Fatal("数据库连接错误: ", err)
		}
		util.Logger.Info("数据库连接成功")
	}
}
